<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class Order extends Resource {
	/**
	 * Transform the resource into an array.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @return array
	 */
	public function toArray($request) {
		return [
			'order_id' => $this->order_id,
			'channel' => $this->whenLoaded('map', function () {
				return $this->map->type->name;
			}),
			'activity' => $this->whenLoaded('map', function () {
				return $this->map->activity->name;
			}),
			'contacts' => $this->contacts,
			'phone' => $this->phone,
			'products' => $this->products,
			'receipt_name' => $this->receipt_name,
			'receipt_address' => $this->receipt_address,
			'order_time' => $this->order_time,
			'price' => $this->price,
			'type' => $this->type == 0 ? '尚未发送短信' : '已发送活动短信',
			'created_at' => \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $this->created_at)->toDateTimeString(),
		];
	}
}
